package com.interesting.client.widget.dialog;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;

import com.actionbarsherlock.app.SherlockDialogFragment;
import com.interesting.base.http.HttpUtil;

/** 举报dialog */
public class ReportDialogFragment extends SherlockDialogFragment implements DialogInterface.OnClickListener {

	String[] items = new String[] { "辱骂", "色情", "广告", "浪费楼层" };

	public ReportDialogFragment newInstance(String commentId, String position, String content) {
		ReportDialogFragment fragment = new ReportDialogFragment();
		Bundle args = new Bundle();
		args.putString("commentId", commentId);
		args.putString("position", position);
		args.putString("content", content);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());

		builder.setTitle("举报" + getArguments().getString("position") + "楼：" + getArguments().getString("content"))
				.setItems(items, this);

		return builder.create();
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {

		new ReportAsync().execute(which+"");
	}

	/** 举报评论 */

	private class ReportAsync extends AsyncTask<String, Void, JSONObject> {

		@Override
		protected JSONObject doInBackground(String... params) {
			Map<String, String> request = new HashMap<String, String>();
			request.put("act", "reportBadness");
			request.put("commentId", getArguments().getString("commentId")); // 评论id
			request.put("content", params[0]);// 举报内容
			return HttpUtil.parseResult(HttpUtil.post(request));
		}

		@Override
		protected void onPostExecute(JSONObject result) {
			if (result != null) {
//				UIUtil.showToast(getSherlockActivity(), "已获得举报信息");
			}
			super.onPostExecute(result);
		}
	}
}
